package users;

import java.io.Serializable;
import java.util.Iterator;
import java.util.TreeMap;

/**
 * 
 * @author Evgeny Pavlenko
 * 
 */

public class Users implements Serializable {
	private TreeMap<String, User> users;

	public Users() {
		users = new TreeMap<String, User>();
	}

	public void add(User user) {
		users.put(user.getName(), user);
	}

	public boolean hasUser(String username) {
		return users.containsKey(username);
	}

	public boolean checkUserPassword(String name, String password) {
		return users.get(name).checkPassword(password);
	}

	public void setUserScore(String name, int score) {
		users.get(name).setScore(score);
	}

	public String getUserScore(String name) {
		return users.get(name).getScore();
	}

	public void assignAdmin(String name) {
		users.get(name).assignAdmin();
	}

	public void assignUser(String name) {
		users.get(name).assignUser();
	}
    public boolean isAdmin(String name){
    	return users.get(name).isAdmin();
    }
    public String getScoreAllUsers()
    {
    Iterator iterator=users.values().iterator();
    String scoreAllUsers="Статистика всех пользователей\n";
    while(iterator.hasNext()){
    	User user=(User) iterator.next();
    	scoreAllUsers+=String.format("%s\n", user.getName());
    	scoreAllUsers+=String.format("%s\n",user.getScore());    	
    }
    return scoreAllUsers;
    }

}
